//
//  ViewController.m
//  LBShowCase
//
//  Created by mac on 2024/6/29.
//

#import "ViewController.h"
#import "LBShowCaseCell.h""
#import "LBNormalCell.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.tableView reloadData];
    // Do any additional setup after loading the view.
}

#pragma mark - UITableViewDelegate, UITableViewDataSource

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSArray <UITableViewCell *> *cells = self.tableView.visibleCells;
    for (UITableViewCell *cell in cells) {
        if ([cell isKindOfClass:[LBShowCaseCell class]]) {
            LBShowCaseCell *showCaseCell = (LBShowCaseCell *)cell;
            [showCaseCell cellOnTableView:self.tableView didScrollView:self.view];
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 4) {
        LBShowCaseCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LBShowCaseCell class])];
        return cell;
    }
    
    LBNormalCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LBNormalCell class])];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 100;
}

#pragma mark - lazy load

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 100) style:UITableViewStylePlain];
        [_tableView registerClass:[LBNormalCell class] forCellReuseIdentifier:NSStringFromClass([LBNormalCell class])];
        [_tableView registerClass:[LBShowCaseCell class] forCellReuseIdentifier:NSStringFromClass([LBShowCaseCell class])];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}


@end
